<?PHP
/**
 * 控制器处理类 test
 */
class Test_Controller extends Controller{
	function __construct(){
		parent::__construct(); 
	 
	} 
	
	function index(){
	 
	}
	function trees(){ 
 		/* 
		[{"id":"22","text":"\u6708\u5ea6\u5de5\u8d44\u7ba1\u7406","leaf":true,"cls":"file","is_a":true},{"id"
:"24","text":"\u5458\u5de5\u5de5\u8d44\u6a21\u677f","leaf":true,"cls":"file","is_a":true},{"id":"23"
,"text":"\u7cfb\u7edf\u6a21\u677f\u8bbe\u7f6e","leaf":true,"cls":"file","is_a":true}]
		 */
		  //sleep(1);
		switch($_POST['node']){
			case "0":
				exit('[
					{"id":"1","text":"江西省","isleaf":"0"},
					{"id":"2","text":"afsd江西省","isleaf":"0"}
				]');
				break;
			case "1":
				exit('[
					{"id":"3","text":"萍乡市","isleaf":"0"},
					{"id":"4","text":"安源市","isleaf":"1"}
				]');
				break;
			case "3":
				exit('[
					{"id":"5","text":"萍乡市","isleaf":"1"},
					{"id":"6","text":"安源市","isleaf":"0"}
				]');
			case "6":
				exit('[
					{"id":"7","text":"萍乡市","isleaf":"1"},
					{"id":"8","text":"安源市","isleaf":"1"}
				]');
				break;
			default:
			  exit('[]');
				break;	
		}
		
		
		exit('{}');
	}
	
	function testajax(){
		print_r($_POST);
		echo 'ajax ok';
		exit();
	}
	 
	function test_autocomplete(){
 
		$items = array(
		"1"=>"周鹏",
		"2"=>"周前",
		"3"=>"里云s",
		"4"=>"哈哈",
		"5"=>"的的大撒法受到按时的啊",
		"6"=>"按时地方离开后大师傅 ",
		"7"=>"十分热额外人额外额外感",
		"8"=>"里云 分热额外",
		"9"=>"里云 minutus",
		"10"=>"Ixobrychus minutus",
		"11"=>"Ixobrychus 里云",
		"12"=>"分热额外 minutus",
		"13"=>"Ixobrychus 的的大撒法受到按时的啊",
		"14"=>"里云 撒旦法上地方"
		);
		
		foreach ($items as $key=>$value) { 
				echo "$key|$value|你输入的查询关键字为'".$_POST['q']."'\n";
			 
		}

	}
	 
 
	/* ajax表格请求数据 */
	function ajax_grid(){
		#得到传递过来的参数
		$_POST=addslash_deep($_POST);
		if(empty($_POST['start']))			$_POST['start']			= 0;
		if(empty($_POST['limit']))			$_POST['limit']			= 10;
		if(empty($_POST['sort']))				$_POST['sort']			= 'a.id';
		if(empty($_POST['dir']))				$_POST['dir']				= 'DESC';
	  
		#查询条件
		$sql_where = ' where 1=1 ';
		  
			
			
		#排序信息
		$sql_order = " ORDER BY ".$_POST['sort'].' '.$_POST['dir']." LIMIT ".$_POST['start'].", ".$_POST['limit'];
 		#先查总数
		$sql = "select count(*) from `#__gathering` a left join `#__agent` b on a.agent_id=b.id ".$sql_where ; 
		
		//$db = getDBO();
//		$rows = $db->LoadResult($sql);
//		if($rows){
//			#检索出具体数据
//			$sql = "select 
//				a.*,
//				DATE_FORMAT(a.opt_date,'%Y-%m-%d') as opt_date,
//				b.name as agent_name,
//				b.login_name as agent_login_name
//			from `#__gathering` a 
//			left join `#__agent` b on a.agent_id=b.id
//			 ".$sql_where.$sql_order;
//			$rs = $db->LoadAssocList($sql);	
//			#输出结果
//			echo '({"total":"'.$rows.'","results":'.loadjson()->encode($rs).'})';
//		}else{
//			echo '({"total":"0","results":[]})';
//		}
		
		//模拟输出一些测试数据
		$rs = array(
			array(
				'id'=>'1',
				'number'=>'0331876',
				'name'=>'周倩',
				'sex'=>'女',
				'classes'=>'03商贸英语',
				'remark'=>'考试满分入学'
			),
			array(
				'id'=>'2',
				'number'=>'0231078',
				'name'=>'XXXX',
				'sex'=>'男',
				'classes'=>'02计算机',
				'remark'=>'天才'
			)
		);
		echo '({"total":"200","results":'.loadjson()->encode($rs).'})';

		exit();
	}	
	
	 
}
?>